Process management.md (1117B)
1 +++ 2 title = 'Process management' 3 +++ 4 # Process management 5 Minimal shell: 6 1. Wait for command 7 2. Start process to execute command 8 3. Wait until process finished 9 10 `pid_t fork()` 11 12 - duplicates current process 13 - negative value — unsuccessful 14 - zero — returned to newly created child process 15 - positive — returned to parent or caller, value is PID of new process 16 17 `pid_t wait(int *wstatus)` 18 19 - waits for child processes to change state 20 - writes status to wstatus 21 22 `int exec(const char *path, char *constargv[])` 23 24 - loads new binary from path in current process 25 - constargv — program arguments 26 - last argument is NULL (e.g. constargv = {“/bin/ls”, “-a”, NULL}) 27 28 signals 29 30 - processes may need to be interrupted 31 - a signal is sent to process that needs to be interrupted 32 - interrupted process catches signal using signal handler 33 - sighandler_t signal(int signum, sighandler_t handler) 34 - registers signal handler 35 - unsignedint alarm(unsigned int secs) 36 - deliver SIGALARM in seconds 37 - `int kill(pd_t pid, int sig)` 38 - deliver signal to pid 39 40 pipes 41 42 - `pipe(fd)` sets up a pipe 43 - fd is array of 2 ints